/*
============================================================================
 Name        : TCPSocketReceiver.h
 Author      : 
 Version     :
 Copyright   : Your copyright notice
 Description : CTCPSocketReceiver declaration
============================================================================
*/

#ifndef TCPSOCKETRECEIVER_H
#define TCPSOCKETRECEIVER_H

// For CActive, link against: euser.lib
// For RTimer, link against: euser.lib
#include <e32base.h>
#include <es_sock.h>
#include <in_sock.h>

const TInt KBuffSizeSOCKET = 1024*8;

class CTCPSocketReceiver : public CActive
{
public: // Observer interface
	class MObserver
	{
	public:
		virtual void OnReceiveL(const TDesC8& aData, TInt aError) = 0;
	};
public:
	// C++ constructor
	CTCPSocketReceiver(MObserver& aObserver, RSocket& aSocket);
	
	// Cancel and destroy
	~CTCPSocketReceiver();

public: // New functions
	// Function for making the initial request
	// void Start(TTimeIntervalMicroSeconds32 aDelay);


private: // From CActive
	// Handle completion
	void RunL();
	void DoCancel();

public: // New functions
	void Receive();
private: // member variables
	MObserver& iObserver;
	RSocket& iSocket;
	TSockXfrLength      iLen;
	TUint8*             iBuffPtr;
	TPtr8               iRecvBuf;       //一定要作为类变量, 否则socket的实现会出现core dump

};

#endif
